﻿// -------------------------------------------------------------------------------------------------------------------------------
// <copyright file="IterationsCountStopCriterion{T}.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>
//     Exul
// </author>
// -------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.Mathematics.LinearAlgebra
{
    #region Usings

    using System;

    #endregion

    /// <summary>
    ///     Provides methods to determine the end of an iteration process using the count of iterations.
    /// </summary>
    /// <typeparam name="T">
    ///     The type of data.
    /// </typeparam>
    public sealed class IterationsCountStopCriterion<T> : IterationsStopCriterion<T>
    {
        #region Constructors and Destructors

        #region public

        /// <summary>
        ///     Initializes a new instance of the <see cref="IterationsCountStopCriterion{T}"/> class.
        /// </summary>
        /// <param name="maxIterationsCount">
        ///     The max iterations count.
        /// </param>
        public IterationsCountStopCriterion(int maxIterationsCount)
        {
            this.MaxIterationsCount = maxIterationsCount;
        }

        #endregion

        #endregion

        #region Properties

        #region public

        /// <summary>
        ///     Gets the max iterations count.
        /// </summary>
        /// <value>
        ///     The max iterations count.
        /// </value>
        public int MaxIterationsCount
        {
            get;
            private set;
        }

        #endregion

        #endregion

        #region Overridden Methods

        #region public

        /// <summary>
        ///     Determines whether an iteration process should be stopped.
        /// </summary>
        /// <param name="data">
        ///     The data describing a current state of the iteration process.
        /// </param>
        /// <returns>
        ///     <see langword="true"/> if the iteration process should be stopped; otherwise, <see langword="false"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="data"/> is <see langword="null"/>.
        /// </exception>
        public override bool ShouldStop(IterationData<T> data)
        {
            #if SAFE

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            #endif

            return this.MaxIterationsCount < data.IterationIndex;
        }

        #endregion

        #endregion
    }
}